package com.nengchuan.kbms.dfs.controller;

import com.nengchuan.model.model.NcPageInfo;
import com.nengchuan.model.model.WrappedResult;
import com.nengchuan.kbms.dfs.entity.FeignDemoDTO;
import com.nengchuan.kbms.dfs.entity.dto.DemoDTO;
import com.nengchuan.kbms.dfs.entity.dto.DemoPageDTO;
import com.nengchuan.kbms.dfs.entity.vo.DemoPageVO;
import com.nengchuan.kbms.dfs.entity.vo.DemoVO;
import com.nengchuan.kbms.dfs.service.DemoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import java.util.List;

/**
 * <p>
 * 示例表 前端控制器
 * </p>
 *
 * @author luoping
 * @since 2020-03-19
 */
@RestController
@RequestMapping("/demo")
@Api(value = "示例", tags = "示例")
public class DemoController {

    @Autowired
    private DemoService demoService;

    @ApiOperation("保存")
    @PostMapping("/insert")
    public WrappedResult<Long> insert(@RequestBody DemoDTO demoDTO) {
        Long id = demoService.insert(demoDTO);
        return WrappedResult.success(id);
    }

    @ApiOperation("修改")
    @PostMapping("/update")
    public WrappedResult<Boolean> update(@RequestBody DemoDTO demoDTO) {
        Boolean result = demoService.update(demoDTO);
        return WrappedResult.success(result);
    }

    @ApiOperation("删除")
    @GetMapping("/delete")
    public WrappedResult<Boolean> delete(@RequestParam Long id) {
        Boolean result = demoService.delete(id);
        return WrappedResult.success(result);
    }


    @ApiOperation("详情")
    @GetMapping("/get")
    public WrappedResult<DemoVO> get(@RequestParam Long id) {
        DemoVO demoVO = demoService.get(id);
        return WrappedResult.success(demoVO);
    }

    @ApiOperation("分页查询")
    @PostMapping("/page")
    public WrappedResult<NcPageInfo<DemoPageVO>> page(@RequestBody DemoPageDTO demoPageDTO) {
        NcPageInfo<DemoPageVO> page = demoService.page(demoPageDTO);
        return WrappedResult.success(page);
    }


    /**** 以下是feign方法 ****/
    @ApiIgnore
    @ApiOperation("根据ids获取列表")
    @PostMapping("/list_by_ids")
    public List<FeignDemoDTO> listByIds(String ids) {
        List<FeignDemoDTO> list = demoService.listByIds(ids);
        return list;
    }

}
